<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=8"><!--以IE8模式渲染-->
	<meta http-equiv="X-UA-Compatible" content="IE=7"><!--以IE7模式渲染-->
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<title>用户新增</title>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/long_add.css">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/easyuiTab/easyui.css">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/easyuiTab/icon.css">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery.alert.v1.2/jquery.alert.css"/>
	<script type="text/javascript" src="__PUBLIC__/js/easyuiTab/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/easyuiTab/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.alert.v1.2/jquery.alert.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/ajax.js"></script>
	<script type="text/javascript">
		$(document).ready(function() 
		{
			var typeId = document.getElementById("type");
			changeType(typeId);
			if(typeId.value == 1) 
			{
				ajaxToBorrow(typeId);
			}
		});

		function changeType(id) 
		{
			var data = {"typeId":id.value};
			var url = "../../invest/invest/invest_add_annex";
			var async = null;
			var type = null;
			var dataType = "html";
			jQuery.ax(url, data, async, type, dataType,
				function(data) 
				{
					$("#invest_change").html(data);
				},
				function(data) 
				{
					jAlert('系统出错！请联系管理员1！','错误提示',null);
				}
			);
		}

		function investSubmit() 
		{
			var typeId = $("#type").val();
			var flag = titleValidate();
			if(typeId == 1) 
			{
				var a = $("#invest_table2").datagrid("getChecked");
				// alert(JSON.stringify(a));
				var idMoneySum = 0;
				for (var i = 0; i < a.length; i++) 
				{
					// console.log(JSON.stringify(a[i].borrow_bid));
					idArray.push(a[i].borrow_bid);
					idMoneySum += parseInt(a[i].borrow_money);
				};
				$("#idArray").val(idArray.toString());
				$("#idMoneySum").val(idMoneySum.toString());
				if(flag & activeTimeValidate() & timeLimitValidate()) 
				{
					if (idArray == '' || !idArray) 
					{
						jAlert('请选择打包项目！','错误提示',function(e){window.location.href='../../invest/invest/invest_add';});
						return false;
					}
					$("#investForm").submit();
				}
			}
			else if(typeId == 3) 
			{
				if(flag & timeLimitValidate() & luckyStarTotalValidate() & luckyStarTotalCountValidate() & luckyRateValidate()) 
				{
					$("#investForm").submit();
				}
			}
		}

		// function investClear() {}

		//	标题验证
		function titleValidate() 
		{
			var value = $("#title").val();
			if(value == null || value == '') 
			{
				jAlert("投资标题不能为空！", '错误提示', null);
				return false;
			}
			else
			{
				return true;
			}
		}

		//	有效时间验证
		function activeTimeValidate() 
		{
			var value = $("#activeTime").val();
			if(value == null || value == '') 
			{
				jAlert("有效时间不能为空！", '错误提示', null);
				return false;
			}
			else
			{
				return true;
			}
		}

		//	投资期数验证#####服务类、幸运星类
		function timeLimitValidate() 
		{
			var value = $("#timeLimit").val();
			if(value == null || value == '') 
			{
				jAlert("投资期数不能为空！", '错误提示', null);
				return false;
			}
			else
			{
				return true;
			}
		}

		//	幸运星验证类#####金额
		function luckyStarTotalValidate() 
		{
			var value = $("#luckyStarTotalAmount").val();
			var reg = new RegExp("^[0-9]*$");  
			if(value == '' || value == null) 
			{
				jAlert("总金额不能为空！",'错误提示',null);
				return false;
			}
			else if(!reg.test(value)) 
			{
				jAlert("总金额必须为数字！",'错误提示',null);
				return false;
			}
			else
			{
				return true;
			}
		}

		//	幸运星验证类#####人数
		function luckyStarTotalCountValidate() 
		{
			var value = $("#luckyStarTotalCount").val();
			var reg = new RegExp("^[0-9]*$");  
			if(value == '' || value == null) 
			{
				jAlert("总人数不能为空！",'错误提示',null);
				return false;
			}
			else if(!reg.test(value)) 
			{
				jAlert("总人数必须为数字！",'错误提示',null);
				return false;
			}
			else
			{
				return true;
			}
		}

		//	幸运星验证类#####收益率
		function luckyRateValidate() 
		{
			var value=$("#luckyStar_rate").val();
			// var reg = new RegExp("^[0-9.]*$");
			if(value ==''||value == null) 
			{
				jAlert("收益率不能为空！",'错误提示',null);
				return false;
			}
			else
			{
				return true;
			}
		}

		// function date(str) 
		// {
		// 	var reg = /^(\d{1,4}\-\d{1,2}\-\d{1,2})$/;
		// 	var r = str.match(reg);
		// 	if(r==null) 
		// 	{
		// 		return true;
		// 	}
		// 	return false;
		// }

		// function success() 
		// {
		// 	jAlert('新增投资项目成功！','新增提示',function(e){
		// 		window.parent.removeTab("投资项目新增","投资管理","../../invest/invest/invest_manage");
		// 	});
		// }

		// function error() 
		// {
		// 	jAlert('新增投资项目失败！请与管理员联系！','新增提示',null);
		// }

		// function myformatter(date) 
		// {
		// 	var y = date.getFullYear();
		// 	var m = date.getMonth()+1;
		// 	var d = date.getDate();
		// 	return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
		// }

		// function myparser(s) 
		// {
		// 	if (!s) return new Date();
		// 	var ss = (s.split('-'));
		// 	var y = parseInt(ss[0],10);
		// 	var m = parseInt(ss[1],10);
		// 	var d = parseInt(ss[2],10);
		// 	if (!isNaN(y) && !isNaN(m) && !isNaN(d)) 
		// 	{
		// 		return new Date(y,m-1,d);
		// 	}
		// 	else
		// 	{
		// 		return new Date();
		// 	}
		// }

		// function algorithmRulesChange() 
		// {
		// 	var loanPeriod=$("#loanPeriod").val();
		// 	if(loanPeriod!='') 
		// 	{
		// 		$("#algorithmRules").find("option[value='"+loanPeriod+"']").attr("selected",true);
		// 	}
		// }

		function timeLimitChange() 
		{
			var loanPeriod = $("#loanPeriod").val();
			if(loanPeriod != '') 
			{
				$("#timeLimit").find("option[value='"+loanPeriod+"']").attr("selected",true);
			}
		}

		var idArray = new Array();
		function ajaxToBorrow(type) 
		{
			if(type == 1) 
			{
				timeLimitChange();
			}
			idArray = new Array();
			var loanGrade = $("#loanGrade").val();
			var loanPeriod = $("#loanPeriod").val();
			// var business = $("#business").val();
			var data = {"loanGrade":loanGrade,"loanPeriod":loanPeriod};
			var url = "../../invest/invest/invest_borrow_annex";
			var async = null;
			var type = null;
			var dataType = "html";
			jQuery.ax(url, data, async, type, dataType, 
				function(data) 
				{
					$("#borrowDetail").html(data);
				},
				function(data) 
				{
					jAlert('系统出错！请联系管理员2！','错误提示',null);
				}
			);
		}
	</script>
</head>
<body>
	<div class="contentPage">
		<form action="../../invest/invest/invest_add" method="post" id="investForm">
			<table class="addForm">
				<tr>
					<th><span>*</span>投资标题：</th>
					<td>
						<input type="text" name="investTitle" id="title">
						<span id="titleSpan"></span>
					</td>
				</tr>
				<tr>
					<th><span>*</span>投资类型：</th>
					<td>
						<select name="investTypeId" id="type" onchange="changeType(this);">
							<?php 
								foreach ($type_array as $key => $value) 
								{
									echo '<option value="'.$value['invest_type_id'].'">'.$value['invest_type_name'].'</option>';
								}
							?>
						</select>
						<span id="typeSpan"></span>
					</td>
				</tr>
			</table>
				
			<div id="invest_change"></div>
		</form>
	</div>
</body>
</html>